import random

from core.models import *
from django.contrib.auth.models import User
from django.utils import timezone
from django.db.models import Avg, Value, CharField, Sum, Count, F, Q, Case, When, Min, Max, OuterRef, Subquery, Exists
from django.db.models.functions import Lower, Concat, Coalesce
from django.db import transaction
import itertools
import time
from django.contrib.contenttypes.models import ContentType


def run():
    content_types = ContentType.objects.filter(app_label='core')
    print(content_types)
    # content_type: ContentType = content_types.get(model='restaurant')
    content_type: ContentType = content_types.get(model='restaurant')
    # restaurant_model: Restaurant = content_type.model_class()  #  an class object
    # print(restaurant_model)  # <class 'core.models.Restaurant'>
    # print(restaurant_model.objects.all())
    restaurant_model: Restaurant = content_type.get_object_for_this_type(name='Taco Bell')
    print(restaurant_model)  # Taco Bell  # an Restaurant instance
    # print(restaurant_model.objects.all())  # error  AttributeError: Manager isn't accessible via Restaurant instances
    print(restaurant_model.latitude)

    rating_content_type = ContentType.objects.get_for_model(Rating)
    print(rating_content_type)

